package com.gujiangbo.redemo;

import com.gujiangbo.serial.Club;
import com.gujiangbo.serialtool.ProtostuffSerializer;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.Date;

public class RedisSerialDemo {
    private Jedis jedis = JedisFactory.getJedis();

    @Test
    public void testSerial() {
        String key = "club:1";
        Club club = new Club();
        club.setId(1);
        club.setName("AC国际米兰");
        club.setCreateDate(new Date());
        club.setInfo("足球俱乐部");
        club.setRank(1);
        //序列化
        byte[] clubBytes = ProtostuffSerializer.serialize(club);
        jedis.set(key.getBytes(), clubBytes);

        //反序列化
        byte[] resultBytes = jedis.get(key.getBytes());
        Club resultClub = ProtostuffSerializer.deserialize(resultBytes);
        System.out.println(resultClub);

    }
}
